package com.ruoyi.wx.controller;

import java.util.Arrays;
import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.wx.domain.WxUser;
import com.ruoyi.wx.service.IWxUserService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 客户信息Controller
 *
 * @author ruoyi
 * @date 2020-05-04
 */
@Controller
@RequestMapping("/wx/user")
public class WxUserController extends BaseController {
    private String prefix = "wx/user";

    @Autowired
    private IWxUserService wxUserService;

    @RequiresPermissions("wx:user:view")
    @GetMapping()
    public String user() {
        return prefix + "/user";
    }

            /**
         * 查询客户信息列表
         */
        @RequiresPermissions("wx:user:list")
        @PostMapping("/list")
        @ResponseBody
        public TableDataInfo list(WxUser wxUser) {
            startPage();
            return getDataTable(wxUserService.list(new QueryWrapper<>(wxUser)));
        }
    
    /**
     * 导出客户信息列表
     */
    @RequiresPermissions("wx:user:export")
    @Log(title = "客户信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WxUser wxUser) {
        List<WxUser> list = wxUserService.list(new QueryWrapper<>(wxUser));
        ExcelUtil<WxUser> util = new ExcelUtil<>(WxUser.class);
        return util.exportExcel(list, "user");
    }

            /**
         * 新增客户信息
         */
        @GetMapping("/add")
        public String add() {
            return prefix + "/add";
        }
    
    /**
     * 新增保存客户信息
     */
    @RequiresPermissions("wx:user:add")
    @Log(title = "客户信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WxUser wxUser) {
        return toAjax(wxUserService.save(wxUser));
    }

    /**
     * 修改客户信息
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap) {
        WxUser wxUser = wxUserService.getById(id);
        mmap.put("wxUser", wxUser);
        return prefix + "/edit";
    }

    /**
     * 修改保存客户信息
     */
    @RequiresPermissions("wx:user:edit")
    @Log(title = "客户信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WxUser wxUser) {
        return toAjax(wxUserService.updateById(wxUser));
    }

            /**
         * 删除客户信息
         */
        @RequiresPermissions("wx:user:remove")
        @Log(title = "客户信息", businessType = BusinessType.DELETE)
        @PostMapping( "/remove")
        @ResponseBody
        public AjaxResult remove(String ids) {
            return toAjax(wxUserService.removeByIds(Arrays.asList(Convert.toStrArray(ids))));
        }
        }
